<template>
    <div class="zx-snippet">
        <div class="zx-snippet--demo">
            <!-- 代码生成vue示例 -->
            <slot name="source" />
        </div>
        <Transition name="fade">
            <div v-show="showCode" class="zx-snippet--code">
                <!-- 示例代码高亮显示 -->
                <slot name="code" />
            </div>
        </Transition>
        <div class="zx-snippet--desc">
            <span class="zx-snippet--icon-code" @click="showCode = !showCode">
                {{ showCode?'隐藏代码':'显示代码' }}
            </span>
        </div>
    </div>
</template>

<script>
import 'highlight.js/styles/color-brewer.css';

export default {
    name: 'ZxSnippet',

    data() {
        return {
            showCode: false,
        };
    },
};
</script>

<style lang="scss">
.zx-snippet {
    position: relative;

    margin: 0 0 16px;
    margin-bottom: 30px;
    box-sizing: border-box;
    border-radius: 4px;
    width: 100%;

    text-align: left;

    background-color: #fff;

    box-shadow: 0 6px 12px -2px rgba(0, 32, 128, .1), 0 0 0 1px #f0f2f7;

    transition: all .2s;
}

.zx-snippet--demo {
    box-sizing: border-box;
    border-bottom: 1px solid #ebedf0;
    padding: 30px 35px;

    font-size: 12px;

    color: #333;
}

.zx-snippet--desc {
    display: flex;

    min-height: 44px;

    align-items: center;
    justify-content: center;
}

.zx-snippet--icon-code {
    line-height: 18px;
    text-align: center;

    color: #ccc;

    cursor: pointer;

    &:hover {
        color: #ff9800;
    }
}
.zx-snippet--code {
    box-sizing: border-box;
    border-top: 1px solid #ebedf0;
    padding: 30px;

    code {
        display: block;

        border: none;
        padding: 16px 32px;

        font-family: Consolas, Menlo, Courier, monospace;
        font-size: 14px;
        line-height: 1.5;

        background: #f9f9f9;
    }

    .hljs {
        margin: 0;
        padding: 20px;
    }
}

.tip {
    margin: 20px 0;
    border-left: 8px solid #1976d2;
    padding: 8px 16px;

    background-color: rgba(25, 118, 210, .05);
}

.warning {
    margin: 20px 0;
    border-left: 8px solid #ff9800;
    padding: 8px 16px;

    background-color: rgba(255, 152, 0, .05);
}

.fade-enter-active,
.fade-leave-active {
    transition: all .1s ease-in-out;
}
.fade-enter,
.fade-leave-to {
    opacity: 0;
}

</style>
